package preprocess;

import java.util.*;

import FlowGraph.*;
import SymbolTable.*;
import FlowGraph.Nodes.*;
import util.Util;
import util.InfoCollector;
import db.ClassData;

//////////////////////////////////////////////////////////////////////////
//// CommonInfoCollector
/**
@author Ivan Jeukens
@version v 0.1 17/10/2002
*/
public class CommonInfoCollector implements InfoCollector {

    public CommonInfoCollector() {
        _getDirectors = new LinkedList();
        _timedDelay = new LinkedList();
    }

    ///////////////////////////////////////////////////////////////////
    ////                         public methods                    ////

    public void visitFGNode(FlowGraphNode node) {
        _checkMethodCalls(node);
    }

    public void visitSTEntry(STEntry entry, FlowGraphNode owner, ClassData info) {
    }

    public Iterator nodeIterator() {
        return _getDirectors.iterator();
    }
    
    public Iterator timedIterator() {
        return _timedDelay.iterator();
    }
    
    public boolean isTimed() {
        return (_timedDelay.size() > 0);
    }

    ///////////////////////////////////////////////////////////////////
    ////                         private methods                   ////

    private void _checkMethodCalls(FlowGraphNode node) {
        if(node.getType() != FlowGraphNode.METHOD_CALL) return;

        MethodCallNode mc = (MethodCallNode) node;

        String mname = mc.getMethodName();
        Class c = mc.getCallerType();
        if(mname != null && c != null) {
            if(mname.equals("getDirector") &&
                    Util.isSubClass(c, ptolemy.actor.AtomicActor.class) ) {
                _getDirectors.add(node);
            }
            else
            if((mname.equals("fireAt") || mname.equals("fireAtCurrentTime")) &&
                   ((c.getClass().equals(ptolemy.actor.Director.class) ) || 
                     Util.isSubClass(c, ptolemy.actor.Director.class)) ) {
                _timedDelay.add(node);
            }
        }

    }

    ///////////////////////////////////////////////////////////////////
    ////                       private variables                   ////

    private LinkedList _getDirectors;
    private LinkedList _timedDelay;
}
